package com.telefonica.bmws.ws;

import java.sql.SQLException;
import com.telefonica.bmws.dao.AfiliaAbonadoDAO;
import com.telefonica.bmws.parameter.AfiliaAbonadoParameter;
import com.telefonica.bmws.result.AfiliaAbonadoResult;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;

import org.apache.log4j.Logger;

@WebService(portName = "AfiliaAbonadoWsPort", serviceName = "AfiliaAbonadoWs", targetNamespace = "http://com.telefonica.bmws.ws", endpointInterface = "com.telefonica.bmws.ws.AfiliaAbonadoWs")
public class AfiliaAbonadoWsImpl implements AfiliaAbonadoWs {

	protected static Logger logger = Logger.getLogger("AfiliaAbonadoWsImpl");
	@Resource
	WebServiceContext wsContext;

	@Override
	@WebMethod
	public String AfiliarAbonado(String arg0, String arg1) throws SQLException {

		MessageContext jaxwsContext = 
				wsContext.getMessageContext();
		HttpServletRequest request = (HttpServletRequest) jaxwsContext.get(SOAPMessageContext.SERVLET_REQUEST);
		String ipAddress = request.getRemoteAddr();
		logger.debug("Client IP consume --> " + ipAddress);
		AfiliaAbonadoDAO dao = new AfiliaAbonadoDAO();
		AfiliaAbonadoResult result = new AfiliaAbonadoResult();
		AfiliaAbonadoParameter parameter = new AfiliaAbonadoParameter();
		parameter.CodigoEntidad = arg1;
		parameter.NumeroCelular = arg0;
		parameter.IpCliente = ipAddress;

		result = dao.AfiliarAbonado(parameter);

		return result.Resultado + "|" + result.Mensaje;

	}
}
